﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPS.SDK.model.oauth
{
    public class UserInfo
    {
        public string nickname;
        public string avatar;
        public string sex;
        public string openid;
        public string unionid;

        public static UserInfo fromJsonObject(JObject jsonObject)
        {
            UserInfo userInfo = new UserInfo();
            JObject userInfoObject = null;
            if (jsonObject["user"] != null)
            {
                userInfoObject = JsonConvert.DeserializeObject<JObject>(jsonObject["user"].ToString());
            }
            if (userInfoObject == null)
            {
                return userInfo;
            }
            userInfo.nickname = userInfoObject["nickname"] == null ? "" : userInfoObject["nickname"].ToString(); 
            userInfo.avatar = userInfoObject["avatar"] == null ? "" : userInfoObject["avatar"].ToString();
            userInfo.sex = userInfoObject["sex"] == null ? "" : userInfoObject["sex"].ToString();
            userInfo.openid = userInfoObject["openid"] == null ? "" : userInfoObject["openid"].ToString();
            userInfo.unionid = userInfoObject["openid"] == null ? "" : userInfoObject["openid"].ToString();
            return userInfo;
        }
    }
}
